package org.jetnuke.modules.blog;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.velocity.VelocityContext;
import org.jetnuke.common.ActionForward;
import org.jetnuke.common.IAction;
import org.jetnuke.common.IAdminInfo;
import org.jetnuke.common.IModuleInfo;
import org.jetnuke.common.IUserInfo;
import org.jetnuke.dao.BlogCommentDAO;
import org.jetnuke.dao.DataAccessDriver;
import org.jetnuke.entities.BlogComment;
import org.jetnuke.entities.BlogPost;
import org.jetnuke.servlets.utilities.StringUtils;
import org.jetnuke.util.JetUtil;

public class UpdateComment implements IAction {
	int id;
	String approved;
	private String author;
	private String email;
	private String author_url;
	private String content;
	public void setId(int id) {
		this.id = id;
	}
	
	public ActionForward exec(HttpServletRequest request,
			HttpServletResponse response, VelocityContext vc, IModuleInfo info,
			String op, IUserInfo ui, IAdminInfo ai) throws Exception {
		BlogCommentDAO bcm=DataAccessDriver.getInst().newBlogCommentDAO();
		BlogComment bc=bcm.retrieveByPK(id);
		int post_id=bc.getPOST_ID();
		BlogPost bp=DataAccessDriver.getInst().newBlogPostDAO().retrieveByPK(post_id);
		int aid=bp.getAID();
		if(ui==null || ui.getID()!=aid)
			return null;
		bc.setAPPROVED(approved);
		bc.setAUTHOR(author);
		bc.setAUTHOR_EMAIL(email);
		bc.setAUTHOR_URL(author_url);
		bc.setCONTENT(content);
		
		bcm.update(bc);
		JetUtil.redirect(vc,response,request.getContextPath()+"/do/blog/show_page?id="+post_id);
		return null;
	}

	public void setApproved(String approved) {
		this.approved = approved;
	}

	public void setAuthor(String author) {
		this.author = StringUtils.filterText(author,true);;
	}

	public void setAuthor_url(String author_url) {
		this.author_url = StringUtils.filterText(author_url,true);
	}

	public void setContent(String content) {
		this.content = StringUtils.filterText(content,false);
	}

	public void setEmail(String email) {
		this.email = StringUtils.filterText(email,true);
	}

}
